package com.zzq.controller;


import com.zzq.entity.Fruit;
import com.zzq.service.FruitService;
import com.zzq.vo.Barvo;
import com.zzq.vo.Pievo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zzq
 * @since 2021-08-22
 */
@RestController
@RequestMapping("/fruit")
public class FruitController {

    @Autowired
    private FruitService fruitService;

    @GetMapping("/list")
    public List<Fruit> list() {
        return this.fruitService.list();
    }

    @DeleteMapping("/deleteFruit/{id}")
    public boolean deleteFruit(@PathVariable("id") Integer id) {
        return this.fruitService.removeById(id);
    }

    @GetMapping("/find/{id}")
    public Fruit findById(@PathVariable("id") Integer id){
        return this.fruitService.getById(id);
    }

    @PutMapping("/update")
    public boolean update(@RequestBody Fruit fruit){
        return this.fruitService.updateById(fruit);
    }

    @PostMapping("/add")
    public boolean addFruit(@RequestBody Fruit fruit){
        return this.fruitService.save(fruit);
    }

    @GetMapping("/barvo")
    private Barvo barvo(){
        return this.fruitService.barvoList();
    }

    @GetMapping("/pievo")
    private List<Pievo> pievo(){
        return this.fruitService.pievoList();
    }

}

